#include "amenduser.h"
#include "ui_amenduser.h"
#include <QDebug>
#include "messagepops.h"
#include "signature.h"
#include "mythread.h"
#include "authenticationpopups.h"
#include <QDir>
#include "md5rc4.h"
#include <QFileDialog>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QHttpPart>
#include "mainwindow.h"
#include <QPainter>
#include <QGraphicsDropShadowEffect>
#include <QtMath>
#include <QListView>
#include <QStyledItemDelegate>
#include <QPushButton>
#include <QCompleter>
#include <QLineEdit>
#include <QStringListModel>
#include <QGraphicsDropShadowEffect>
#include "hintwindow.h"
#include <QTimer>
#include "messagepops.h"
#include "lcombobox.h"
#include "showsignature.h"
#include "operationdocument.h"
#include "function/function.h"

int ifDigitalVein2;//指静脉id(0->未采集成功,1->采集成功)


amendUser::amendUser(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::amendUser)
{
    ui->setupUi(this);

    this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明
    this->setWindowFlags(Qt::FramelessWindowHint|Qt::Window);   //设置无边框窗口
//    this->setWindowFlags(Qt::Window);//将子窗口设置为非顶级窗口

    QWidget *parentWidget=this->parentWidget();
    QPoint globalPos = parentWidget->mapToGlobal(QPoint(0,0));//父窗口绝对坐标
    int x = globalPos.x() + (parentWidget->width() - this->width()) / 2;//x坐标
    int y = globalPos.y() + (parentWidget->height() - this->height()) / 2;//y坐标
    this->move(x, y);//窗口移动

    //设置具体阴影
    QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);
    shadow_effect->setOffset(0, 0);

    //阴影颜色
    shadow_effect->setColor(QColor(38, 78, 119, 127));
    //阴影半径
    shadow_effect->setBlurRadius(10);
    ui->label_9->setGraphicsEffect(shadow_effect);

    //创建一个文件夹存放用户指静脉信息文件,已经存在返回true
    QDir dir;
    QString myPath=QString("%1%2").arg(MY_PATH).arg("getFingerprints");
    dir.mkpath(myPath);

    initialize();

//    thread=new mythread(this); //初始化线程对象
    aps=new AuthenticationPopups(this);
    aps->hide();

    hintw=new HintWindow(this);
    hintw->setGeometry(80,470,310,90);
    hintw->hide();

    //初始化定时器对象
    hinttime=new QTimer(this);
    //设置定时时间
    hinttime->setInterval(3000);  //3秒
    //关联timeout()信号与自定义的槽函数
    connect(hinttime,SIGNAL(timeout()),this,SLOT(hinttimer()));

    //初始化定时器对象
    deletetime=new QTimer(this);
    //设置定时时间
    deletetime->setInterval(100);  //0.1秒
    //关联timeout()信号与自定义的槽函数
    connect(deletetime,SIGNAL(timeout()),this,SLOT(deletetimer()));

    mps=new MessagePops(this);//初始化提示窗口对象
    mps->hide();
    mps->setGeometry(100,200,270,220);
    connect(mps,SIGNAL(sendMessage(QString)),this,SLOT(receMessage(QString)));

    mps2=new MessagePops(this);//初始化提示窗口对象(不关联信号与槽)
    mps2->hide();
    mps2->setGeometry(100,200,270,220);
}

amendUser::~amendUser()
{
    delete ui;
}

void amendUser::setThread(mythread *thread_,QByteArray bytes_,QStringList accountNumber_,QWidget *widget)
{
    bytes = bytes_;
    thread = thread_;
    connect(thread,SIGNAL(sendThUserData(int,QString)),this,SLOT(receThUserData(int,QString)));
    accountNumbers=accountNumber_;
    qmain = widget;
}

//设置用户基础信息 (姓名，性别，账号)
void amendUser::setUser(QString gatherName_, QString gender_, QString accountNumber_ ,int digital_vein_device_id_,QString role,QString phone,QString path)
{
    gatherName = gatherName_;
    gender = gender_;
    accountNumber = accountNumber_;
    digital_vein_device_id = digital_vein_device_id_;
    signature_path = path;

    ui->label_13->setText(gatherName);
    ui->label_14->setText(gender);
    ui->label_15->setText(accountNumber);
    lComboBox2->setCurrentRow(role);
//    qDebug()<<__LINE__<<path;
    ui->lineEdit_3->setText(phone);
}

void amendUser::hinttimer()
{
    hinttime->stop();//关闭定时器

    hintw->hide();//隐藏指静脉窗口提示
}

void amendUser::deletetimer()
{
    deletetime->stop();//关闭定时器

    delete this;
}

//http发送指静脉信息接收槽函数
void amendUser::requestFinishedFile(QNetworkReply *reply)
{
//    //1、获取响应状态码
//    QVariant variant = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
//    if (variant.isValid())
//    {
//        qDebug() << variant.toInt();
//    }
//    //2、获取响应头
//    variant = reply->header(QNetworkRequest::ContentTypeHeader);
//    if (variant.isValid())
//        qDebug() << variant.toString();

    //3、获取响应信息
    QByteArray bytes = reply->readAll();

    qDebug()<<__LINE__<<QString(bytes);

    //把获取的json数据标准化存储
    QJsonParseError myerr;
    QJsonDocument mydoc=QJsonDocument::fromJson(bytes,&myerr);

    //获取最外面的对象
    QJsonObject obj=mydoc.object();

    QString retInfo=obj.value("message").toString();
    if(retInfo == "修改成功")
    {
        if(ifDigitalVein2 > 0)
        {
            //删除用户原来的指静脉信息
            thread->DeletingUsersOne(digital_vein_device_id);
        }

        mps->setText("修改成功");
        mps->show();
    }
    else
    {
        mps->setText("修改失败");
        mps->show();
    }

    if(multiPart != nullptr)
    {
        delete multiPart;
        multiPart=nullptr;
    }

    if(ifDigitalVein2 > 0)
    {
        file->close();
    }
    if(ifSignature == 1)
    {
        file1->close();
    }


}

//点击关闭按钮
void amendUser::on_pushButton_5_clicked()
{
    if(ifDigitalVein2 > 0)
    {
        //没有录入该用户，删除指静脉信息
        thread->DeletingUsersOne(ifDigitalVein2);
    }

    emit sendAmendMan("2");
    deletetime->start();//开启关闭窗口定时器
}

//点击校验指纹
void amendUser::on_pushButton_clicked()
{   
    aps->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);
    aps->setLibel3("第一步：校验");
    aps->setLibel2("");
    aps->show();

    thread->getWindowOpenBox(4,digital_vein_device_id);//该功能为编号4
    thread->getWindowPointer(aps);//穿提示窗口指针
//    thread->setGainUid(uidList);//把UID传过去
    thread->start();  //开启一个线程,线程自动帮我执行run
//    thread->verification1_1(&digital_vein_device_id);
}

//点击签名按钮
void amendUser::on_pushButton_2_clicked()
{
    signature *sn=new signature(this);
    sn->show();
    //关联timeout()信号与自定义的槽函数
    connect(sn,SIGNAL(sendSignaDestroy(QString)),this,SLOT(receSignaDestroy(QString)));
    signaturePath=QString("%1%2").arg(MY_PATH).arg("签名.jpg");
}

//点击打开签名按钮
void amendUser::on_pushButton_3_clicked()
{
    //弹出文件对话框
    signaturePath=QFileDialog::getOpenFileName(this,"选择电子签名",MY_PATH,"Images(*.jpg *.png *.xpm *.bmp)");

    if(signaturePath.isEmpty())
    {
        //未选择签名图片

    }
    else
    {
        ifSignature=1;
        ifInformationIntegrity();

//        ui->label_12->setGeometry(130,484,23,22);
//        ui->label_12->show();
//        ui->pushButton_2->setGeometry(180,480,100,30);
//        ui->pushButton_3->setGeometry(300,480,100,30);
    }
}

//自定义完成签名接收槽函数
void amendUser::receSignaDestroy(QString data)
{
    if(data == "1:yes")
    {
        ifSignature = 1;//完成签名
        ifInformationIntegrity();
//        ui->label_12->setGeometry(130,484,23,22);
//        ui->label_12->show();
//        ui->pushButton_2->setGeometry(180,480,100,30);
//        ui->pushButton_3->setGeometry(300,480,100,30);
    }
}

void amendUser::receThUserData(int n, QString data)
{
    if(n == 1)
    {
        QStringList mylist = data.split("@#");
        if(mylist.size() >= 2)
        {
            //指静脉信息采集成功
            setHint(mylist.at(1),1);
//            ui->pushButton->setGeometry(210,420,100,30);
//            ui->pushButton->setText("重新采集");
//            ui->label_11->setGeometry(130,420,60,30);
//            ui->label_11->show();
        }
        else
        {
            setHint(data,0);
        }

        ifInformationIntegrity();
    }
    else if(n == 4)
    {
        QStringList mylist = data.split("@#");
        if(mylist.size() >= 2)
        {
            //1:1验证成功
            ifVerify = 1;
            setHint(mylist.at(1),1);
        }
        else
        {
            setHint(data,0);
        }

        ifInformationIntegrity();
    }
}

//自定义提示窗口接收槽函数
void amendUser::receMessage(QString data)
{
    if(data == "1")
    {
        emit sendAmendMan("1");
        deletetime->start();//开启关闭窗口定时器
//        delete mps;
//        delete this;
    }

}

void amendUser::receLComboBox2(int n, QString)
{
    if(n == 1)
    {
        ifInformationIntegrity();
    }
}

//初始化界面
void amendUser::initialize()
{
//    //隐藏获取信息后的提示语
//    ui->label_11->hide();
//    ui->label_12->hide();

    //联系方式只能输入数字
    ui->lineEdit_3->setValidator(new QRegExpValidator(QRegExp("[0-9]+$")));

    ui->lineEdit_3->setMaxLength(11);//限制联系方式最多只能输入11位

    OperationDocument::setqss(ui->lineEdit_3,":/new/prefix1/resource/myStyleSheet2.qss");

    //设置QComboBox样式
//    setcomboBox(ui->comboBox);
    setcomboBox(ui->comboBox_2);

    lComboBox2 = new LComboBox(this);
    connect(lComboBox2,SIGNAL(sendLComboBox(int,QString)),this,SLOT(receLComboBox2(int,QString)));
    lComboBox2->setGeometry(130,216,150,30);
    QStringList list2;
    list2<<"医生"<<"护士"<<"主任"<<"毒麻管理护士";
    lComboBox2->setTexe(list2);

    QFont font;
    font.setLetterSpacing(QFont::PercentageSpacing,120);//120字间距，默认100
    ui->label->setFont(font);
    ui->label_2->setFont(font);
    ui->label_3->setFont(font);
    ui->label_4->setFont(font);
    ui->label_5->setFont(font);
    ui->label_6->setFont(font);
    ui->label_7->setFont(font);
    ui->label_8->setFont(font);
    ui->label_9->setFont(font);
    ui->label_10->setFont(font);
    ui->label_11->setFont(font);
    ui->label_12->setFont(font);
    ui->label_13->setFont(font);
    ui->label_14->setFont(font);
    ui->label_15->setFont(font);
    ui->pushButton_6->setFont(font);
    ui->lineEdit_3->setFont(font);

    //禁用确定按钮
    ifInformationIntegrity();
}

//设置QComboBox样式
void amendUser::setcomboBox(QComboBox *comboBox)
{
    comboBox->setView(new  QListView());

    //设置标题字间距,外阴影
    QFont font;
    font.setLetterSpacing(QFont::PercentageSpacing,120);//120字间距，默认100
    QAbstractItemView* view = comboBox->view();
    view->setFont(font);//设置标题字间距
    QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect;
    effect->setBlurRadius(10);//阴影半径
//    effect->setColor(Qt::black);
    effect->setColor(QColor(38, 78, 119, 127));//阴影颜色
    effect->setOffset(0, 0);
    view->setGraphicsEffect(effect);
    view->update();

    static_cast<QMainWindow*>(view->parent())->setStyleSheet("QMainWindow{border:none;background-color: rgb(255, 255, 255);}");

    QMainWindow* container = static_cast<QMainWindow*>(view->parent());
//    container->setAttribute(Qt::WA_TranslucentBackground);
    container->setWindowFlag(Qt::FramelessWindowHint);
    container->setWindowFlag(Qt::NoDropShadowWindowHint);
}

//指静脉提示信息窗口 data->提示语 (0->错误提示图标,1->正确提示图标)
void amendUser::setHint(QString data, int n)
{
    hintw->setText(data);
    hintw->setPicture(n);
    hintw->show();

    //开启定时器显示3秒
    hinttime->start();
}

//判断输入用户信息是否完整(-1->不完整,1->完整)
int amendUser::ifInformationIntegrity()
{

    //获取QComboBox列表项的当前项的文字
//    gender=ui->comboBox->currentText();//性别
    permission=comboBoxText(lComboBox2);//权限

//    gatherName=ui->lineEdit->text();//姓名
//    accountNumber=ui->lineEdit_2->text();//账号
    contactInformation=ui->lineEdit_3->text();//联系方式

    if(permission.isEmpty())
    {
        //信息未完善，禁止点击完成按钮
        ui->pushButton_4->setEnabled(false);
        ui->pushButton_4->setStyleSheet("background: #CCCCCC;color: rgb(251, 251, 251);font-size: 18px;font-family: Microsoft YaHei;border-bottom-left-radius :16px;border-bottom-right-radius :16px;");
        return -1;
    }
//    if(gatherName.isEmpty())
//    {
//        //信息未完善，禁止点击完成按钮
//        ui->pushButton_4->setEnabled(false);
//        ui->pushButton_4->setStyleSheet("background: #CCCCCC;color: rgb(251, 251, 251);font-size: 18px;font-family: Microsoft YaHei;border-bottom-left-radius :16px;border-bottom-right-radius :16px;");
//        return -1;
//    }
//    if(accountNumber.isEmpty())
//    {
//        ui->pushButton_4->setEnabled(false);
//        ui->pushButton_4->setStyleSheet("background: #CCCCCC;color: rgb(251, 251, 251);font-size: 18px;font-family: Microsoft YaHei;border-bottom-left-radius :16px;border-bottom-right-radius :16px;");

//        return -1;
//    }
    if(contactInformation.isEmpty())
    {
        ui->pushButton_4->setEnabled(false);
        ui->pushButton_4->setStyleSheet("background: #CCCCCC;color: rgb(251, 251, 251);font-size: 18px;font-family: Microsoft YaHei;border-bottom-left-radius :16px;border-bottom-right-radius :16px;");

        return -1;
    }
//    if(ifSignature==0)
//    {
//        ui->pushButton_4->setEnabled(false);
//        ui->pushButton_4->setStyleSheet("background: #CCCCCC;color: #FBFBFB;font: 11pt \"Microsoft YaHei UI\";border-bottom-left-radius :16px;border-bottom-right-radius :16px;");

//        return -1;//未完成签名
//    }
//    if(ifDigitalVein2 <= 0)
//    {
//        ui->pushButton_4->setEnabled(false);
//        ui->pushButton_4->setStyleSheet("background: #CCCCCC;color: #FBFBFB;font: 11pt \"Microsoft YaHei UI\";border-bottom-left-radius :16px;border-bottom-right-radius :16px;");

//        return -1;//未完成指静脉
//    }

    ui->pushButton_4->setEnabled(true);
    ui->pushButton_4->setStyleSheet("background: #1B89CC;color: rgb(251, 251, 251);font-size: 18px;font-family: Microsoft YaHei;border-bottom-left-radius :16px;border-bottom-right-radius :16px;");

    return 1;
}

//把指静脉信息写入文件中保存
void amendUser::WriteDigitalInformation()
{
    Md5Rc4 *mr=new Md5Rc4();//初始化加解密对象
//    mythread *thread=new mythread(this); //初始化线程对象

    char sTemp[10240] = { 0 };

    //设置用户初始信息
    QString sUser1Info=QString("NAME:%1,ADMIN:0,DEPART:0,CARDNO:0,WORKNO:0,PASSWORD:0,UID:%2").arg(gatherName).arg(ifDigitalVein2);
    thread->getWriteDevInfo(ifDigitalVein2,sUser1Info);
    //获取用户指静脉信息
    thread->getDigitalInformation(ifDigitalVein2,sTemp);

    //把两段信息拼接用md5加密
    QString proclaimedWriting=QString("%1%2").arg(sTemp).arg(sUser1Info);//拼接得到明文
    QString md5=mr->md5Encryption(proclaimedWriting);//得到密文

    //把指静脉信息用rc4加密
    unsigned long len = strlen(sTemp);
    qDebug()<<"len="<<len;
    mr->rc4EncryptionDecode(sTemp, len);
    QByteArray array=QByteArray(sTemp,len);

    QFile myfile;
    filePath=QString("%1/getFingerprints/%2_%3.txt").arg(MY_PATH).arg(gatherName).arg(ifDigitalVein2);//姓名_uid.txt命名文件
    myfile.setFileName(filePath);

    //把原文件清空覆盖
    myfile.open(QIODevice::ReadWrite|QIODevice::Truncate);
    //把刚才修改好的内容写入到该文件中
    QByteArray ar=array.toHex();
    myfile.write(ar);
    myfile.write("\n");
    myfile.close();

    QString allContent=QString("%1\n%2").arg(sUser1Info).arg(md5);//拼接得到文件的全部内容

    //把原文件追加打开
    myfile.open(QIODevice::ReadWrite|QIODevice::Append);
    //把刚才修改好的内容写入到该文件中
    myfile.write(allContent.toUtf8());
    myfile.close();
}

//发送采集到的指静脉文件
void amendUser::sendFingerVeinFile()
{
    //构造manager发送文件
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    // 连接信号槽
    connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(requestFinishedFile(QNetworkReply *)));

    //构造multiPart ，用来组装文件数据
    multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

    if(ifDigitalVein2 > 0)
    {
        //添加指静脉文件信息
        QHttpPart imagePart;
        QFileInfo fileinfo(filePath);
        QString filename = fileinfo.fileName();//传输的文件名称
        //此ContentDispositionHeader参数极为重要，如果不对，则发送不成功，name可以随意起名字，但是filename则必须是你要上传的文件名。//姓名@性别@权限@账号@联系方式@id@文件名称
    //    imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
        imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QString("form-data; name=\"%1\"; filename=\"%2\"").arg("f1").arg(filename));
        file = new QFile(filePath);//采集的指静脉信息文件路径
        file->open(QIODevice::ReadOnly);

        //依照下面方式将文件的内容附着于multiPart上
        imagePart.setBodyDevice(file);
        file->setParent(multiPart);
        multiPart->append(imagePart);
    }


    if(ifSignature == 1)
    {
        //添加签名信息
        QString filePath1=QString("%1签名.jpg").arg(MY_PATH);
        QHttpPart imagePart1;
        QFileInfo fileinfo1(filePath1);
        QString filename1 = fileinfo1.fileName();//传输的文件名称
        //此ContentDispositionHeader参数极为重要，如果不对，则发送不成功，name可以随意起名字，但是filename则必须是你要上传的文件名。//姓名@性别@权限@账号@联系方式@id@文件名称
    //    imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
        imagePart1.setHeader(QNetworkRequest::ContentDispositionHeader, QString("form-data; name=\"%1\"; filename=\"%2\"").arg("f1").arg(filename1));
        file1 = new QFile(filePath1);//采集的指静脉信息文件路径
        file1->open(QIODevice::ReadOnly);
        //构造multiPart ，用来组装文件数据
        QHttpMultiPart *multiPart1 = new QHttpMultiPart(QHttpMultiPart::FormDataType);
        //依照下面方式将文件的内容附着于multiPart上
        imagePart1.setBodyDevice(file1);
        file1->setParent(multiPart1);
        multiPart->append(imagePart1);
    }


    //添加用户信息
    QString userinfo=QString("gatherName=%1@gender=%2@permission=%3@accountNumber=%4@contactInformation=%5@UserId=%6").arg(gatherName).arg(gender).arg(permission).arg(accountNumber).arg(contactInformation).arg(ifDigitalVein2);
    QHttpPart textPart;
//    textPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain"));
    textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\""));
    textPart.setBody(userinfo.toUtf8());
    multiPart->append(textPart);
    qDebug()<<__LINE__<<"userinfo.toUtf8()="<<QString(userinfo.toUtf8());

    //此处设置上传的url
    QNetworkRequest request(QUrl(URLName_2("update-user/")));
//    qDebug()<<__LINE__<<"bytes="<<bytes;
    request.setRawHeader("token",bytes);
//    request.setRawHeader("userinfo",userinfo.toUtf8());

    //发送post
    manager->post(request, multiPart);
}

QString amendUser::comboBoxText(LComboBox *comboBox)
{
    return comboBox->text();
}

//点击确定按钮
void amendUser::on_pushButton_4_clicked()
{
//    //检查账号是否重复
//    for(int i=0; i<accountNumbers.size(); i++)
//    {
//        if(accountNumbers.at(i) == accountNumber)
//        {
//            mps2->setText("账号已存在");
//            mps2->show();
//            return;
//        }
//    }

    if(ui->lineEdit_3->text().size()!=11 || ui->lineEdit_3->text().mid(0,1)!="1")
    {
        mps2->setText("联系方式格式不正确");
        mps2->show();
        return;
    }

    mps->setText0("正在上传信息");
    mps->show();

    if(ifDigitalVein2 > 0)
    {
        //把指静脉信息写入文件中保存
        WriteDigitalInformation();
    }


    //把指静脉信息发送给中央系统
    sendFingerVeinFile();




}

////当姓名输入框QLineEdit中的文本改变时，发出此信号，text是新的文本。当通过程序改变文本时，也会触发此信号
//void amendUser::on_lineEdit_textChanged(const QString &)
//{
//    ifInformationIntegrity();
//}

////当账号输入框QLineEdit中的文本改变时，发出此信号
//void amendUser::on_lineEdit_2_textChanged(const QString &)
//{
//    ifInformationIntegrity();
//}

//当联系方式输入框QLineEdit中的文本改变时，发出此信号
void amendUser::on_lineEdit_3_textChanged(const QString &arg1)
{
    if(arg1.isEmpty())
    {
        OperationDocument::setqss(ui->lineEdit_3,":/new/prefix1/resource/myStyleSheet2.qss");

//        ui->lineEdit_3->setStyleSheet("border: 1px solid #666666;border-radius: 8px;padding-left:8px;padding-bottom:2px;font-size: 16px;font-family: Microsoft YaHei;color: #999999;");
    }
    else
    {
        OperationDocument::setqss(ui->lineEdit_3,":/new/prefix1/resource/myStyleSheet.qss");

//        ui->lineEdit_3->setStyleSheet("border: 1px solid #666666;border-radius: 8px;padding-left:8px;padding-bottom:2px;font-size: 16px;font-family: Microsoft YaHei;color: #333333;");
    }

    ifInformationIntegrity();
}

//点击采集指纹按钮
void amendUser::on_pushButton_6_clicked()
{
    aps->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);
    aps->setLibel3("第二步：重新采集");
    aps->show();


    thread->getWindowOpenBox(3);//该功能为编号3
    thread->getWindowPointer(aps);//穿提示窗口指针
//    thread->setGainUid(uidList);//把UID传过去
    thread->start();  //开启一个线程,线程自动帮我执行run
}

void amendUser::on_label_12_clicked()
{
    if(ifSignature == 1)
    {
        //重新签名了，显示新的图片
        int x = qmain->x();
        int y = qmain->y();
        int w = qmain->width();
        int h = qmain->height();
        ShowSignature *showsig = new ShowSignature(this);
        showsig->shsize(x, y, w, h);

        showsig->setPixmap(signaturePath);
        showsig->show();
    }
    else
    {
        //找服务器显示当前图片
        if(!signature_path.isEmpty())
        {
            QString URL_Name=URLName(QString("/upload/%1").arg(signature_path));//获取文件http网址

            QNetworkAccessManager *manager=new QNetworkAccessManager(this);
//            connect(&manager,SIGNAL(finished(QNetworkReply *)),this,SLOT(recvhttp(QNetworkReply *)));//关联finished信号

            QUrl url(URL_Name);
            //创建http请求
            QNetworkRequest req(url);
//             req.setRawHeader("token",bytes);
            //发送该请求
            reply=manager->get(req);

//            receDigitalVeinUser++;
            //下面关联信号和槽
            connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));//下载完成后
            connect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead()));//有可用数据时
            qDebug()<<__LINE__<<"准备下载签名图片"<<URL_Name;
        }
    }

}

void amendUser::httpFinished()
{
    qDebug()<<__LINE__<<"签名图片下载完成";
    reply->deleteLater();
    reply = 0;

    QPixmap map;
    map.loadFromData(signatureImage);

    int x = qmain->x();
    int y = qmain->y();
    int w = qmain->width();
    int h = qmain->height();
    ShowSignature *showsig = new ShowSignature(this);
    showsig->shsize(x, y, w, h);

    showsig->setPixmap(map);
    showsig->show();
}

void amendUser::httpReadyRead()
{
    QByteArray buf = reply->readAll();
    signatureImage.append(buf);
}
